﻿using System;
using System.Net;
using Ninject;
using Ninject.Syntax;
using Ninject.Modules;
using WebSiteAdminTool.Common.Utils;

namespace WebSiteAdminTool.Common.Ioc
{
    public abstract class BaseLocator
    {
        #region private data

        protected Constants.ApplicationModes _applicationMode = Constants.ApplicationModes.Design;
        protected StandardKernel _bindings = null;

        #endregion

        #region ctors

        public BaseLocator(Constants.ApplicationModes ApplicationMode)
        {
            // initilize mappings
            // TODO: Use DI technique to inject mappings
            INinjectModule mappings = null;
            switch (ApplicationMode)
            {
                case Constants.ApplicationModes.Design:
                    mappings = GetDesignTimeBindings();
                    break;
                case Constants.ApplicationModes.RunTime:
                    mappings = GetRunTimeBindings();
                    break;
                case Constants.ApplicationModes.Testing:
                    mappings = GetTestTimeBindings();
                    break;
            }

            _bindings = new StandardKernel(mappings);
        }

        #endregion

        #region public & protected props

        protected virtual Constants.ApplicationModes ApplicationMode
        {
            get
            {
                return _applicationMode;
            }
        }

        #endregion

        #region helpers

        protected virtual INinjectModule GetTestTimeBindings()
        {
            throw new NotImplementedException();
        }

        protected virtual INinjectModule GetRunTimeBindings()
        {
            throw new NotImplementedException();
        }

        protected virtual INinjectModule GetDesignTimeBindings()
        {
            throw new NotImplementedException();
        }

        protected T GetObject<T>()
        {
            return _bindings.Get<T>();
        }

        protected T GetObject<T>(string bingingName)
        {
            return _bindings.Get<T>(bingingName);
        }

        #endregion
    }
}
